<!DOCTYPE html>
<html>
	<head lang="en">
		<meta charset="UTF-8">
		<title>超市订单管理系统</title>
		<link type="text/css" rel="stylesheet" href="../css/style.css" />
		<link type="text/css" rel="stylesheet" href="../css/public.css" />
		<style>
			body{
				background-color: white;
			}
		</style>
	</head>
	<body>
		<div class="location">
			<strong>你现在所在的位置是:</strong>
			<span>用户管理页面 &gt;&gt; 用户添加页面</span>
		</div>
		<div class="providerAdd">
			<form id="userForm" name="userForm" method="post" action="">
				<div>
					<label for="imgButton">头像：</label><img width="200px" id="img"/>
					<input  type="file" name="imgButton" id="imgButton" onchange="upload()">
				</div>
				<div>
					<label for="userCode">用户编码：</label>
					<input required type="text" name="userCode" class="text" id="userCode" />
					<font color="red">*</font>
				</div>
				<div>
					<label for="userName">用户名称：</label>
					<input required type="text" name="userName" id="userName" />
					<font color="red">*</font>
				</div>
				<div>
					<label for="userPassword">用户密码：</label>
					<input required type="text" name="userPassword" id="userPassword" />
					<font color="red">*</font>
				</div>
				<div>
					<label for="phone">手机号码：</label>
					<input required type="text" name="phone" id="phone" />
					<font color="red">*</font>
				</div>
				<div>
					<label for="address">地址：</label>
					<input required type="text" name="address" id="address" />
					<font color="red">*</font>
				</div>
				<div>
					<label for="birthday">生日：</label>
					<input required type="date" name="birthday" id="birthday" />
					<font color="red">*</font>
				</div>
				<div>
					<label>角色：</label>
					<select name="userRole" id="role-list">
						<option value="0">请选择</option>
					</select>
					<font color="red">*</font>
				</div>
				<div>
					<label>性别：</label>
					<input type="radio" name="gender" value="2" checked="checked" />男
					<input type="radio" name="gender" value="1" />女
					<font color="red">*</font>
				</div>
				<div class="providerAddBtn">
					<input type="submit" name="add" id="add" value="保存" onclick="checkForm('add')"/>
					<input type="button" id="back" name="back" value="返回" onclick="history.go(-1)" />
				</div>
			</form>
		</div>

		<script src="../js/jquery-3.5.1.js"></script>
		<script src="../js/jquery.form.js"></script>
		<script src="../js/common.js"></script>
		<script>
			loadData_role();

			//绑定表单提交事件
			$("form").submit(function () {
				var params={"imgSrc":$("#img").attr("src")};
				//用ajax方式提交表单
				$("form").ajaxSubmit({
					url: "../user/addUser",
					type: "post",
					dataType: "json",
					data:params,
					success: function (result) {
						if (result.flag) {
							alert(result.msg);
							//跳转到用户列表
							location.href = "user_list.html";
						} else {
							alert(result.msg);
						}
					},
					error: function (jqxhr) {
						alert("请求出错：" + jqxhr.status);
					}
				});

				//阻止事件继续传递，停止表单的继续提交
				return false;
			})
		</script>
	</body>
</html>
